/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import service.User;

/**
 *
 * @author CIAO
 */
public class SpringApp extends MultiActionController {

    private service.User userManager;
    private ModelMap model;

    public User getUserManager() {
        return userManager;
    }

    public void setUserManager(User userManager) {
        this.userManager = userManager;
    }

    public ModelAndView index(HttpServletRequest request, HttpServletResponse respone) throws Exception {
        model = new ModelMap();
        try {
            model.addAttribute("users", userManager.getAll());
        } catch (Exception e) {
            model.addAttribute("error", e.getMessage());
            System.out.println("Error : " + e.getMessage());
        }
        return new ModelAndView("index", model);
    }

    public ModelAndView detail(HttpServletRequest request, HttpServletResponse respone) throws Exception{
        model = new ModelMap();
        model.addAttribute("u", userManager.getDetail(Integer.parseInt(request.getParameter("id"))));
        return new ModelAndView("detail", model);
    }
}
